import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
export default new Vuex.Store({

  state: {
    goodlist: [],
    i: 1
  },
  mutations: {
    // 请求到的数据
    goodlist(state, data) {
      state.goodlist = data
    },

  },
  getters: {
    // 计算总价
    sum(state) {
      let sum = 0
      state.goodlist.forEach(item => {
        if (item.checked == true) {
          sum += item.productPrice * item.productCount
        }
      })
      return sum
    },
  },
  actions: {
  },
  modules: {
  }
})
